package model;

import java.util.ArrayList;

/***
 * Class which represents a method of a class, with a name, access and parameters
 * @author Federico
 *
 */
public class Method {
	
	private String name;
	
	//0 = private, 1 = public, 3 = parameter
	private int access;
	private ArrayList<Attribute> parameters;
	
	public Method(String n, int a){
		name = n;
		if(a >= 0 && a <= 3)
			access=a;
		parameters = new ArrayList<Attribute>();
	}
	
	public Method(String n, ArrayList<Attribute> p){
		name = n;
		parameters = p;
	}
	
	public void addParameter(String n){
		parameters.add(new Attribute(n));
	}
	
	public void addParameter(Attribute a){
		parameters.add(a);
	}

	public String getName() {
		return name;
	}

	public ArrayList<Attribute> getParameters() {
		return parameters;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setParameters(ArrayList<Attribute> parameters) {
		this.parameters = parameters;
	}
	
	public int getAccess() {
		return access;
	}

	public void setAccess(int access) {
		this.access = access;
	}

	public boolean isPublic(){
		return access==1;
	}
	
	public boolean isPrivate(){
		return access==0;
	}
	
	public String toString(){
		String pars="";
		if(!parameters.isEmpty()){
			for(Attribute a : parameters)
				pars+= a.getName()+" ,";
			pars = pars.substring(0, pars.length()-1);//Remove the coma
		}
		String acc;
		if(isPublic())acc="+";
		else acc="-";
		return acc+name+"( "+pars+" )";
	}
}
